package com.oyjd.framework.ui.title;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oyjd.R;

/**
 * 封装了标题功能
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class TitleBar extends LinearLayout {
	private LayoutInflater flater;// 布局加载器
	private Button title_left_bt;// 左边按钮
	private TextView title_txt;// 标题

	/**
	 * 构造函数
	 * 
	 * @param context
	 */
	public TitleBar(Context context) {
		super(context);
		init();
	}

	/**
	 * 构造函数
	 * 
	 * @param context
	 * @param attrs
	 */
	public TitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	/**
	 * 初始化
	 */
	private void init() {
		// 初始化布局加载器
		flater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		flater.inflate(R.layout.inner_title_bar, this, true);

		title_txt = (TextView) this.findViewById(R.id.title_txt);
		title_left_bt = (Button) this.findViewById(R.id.title_left_bt);
		title_left_bt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (getContext() instanceof Activity) {
					((Activity) getContext()).finish();
				}
			}
		});
	}

	/**
	 * 设置回退是否可见
	 * 
	 * @param visiable
	 */
	public void setBackVisiable(boolean visiable) {
		title_left_bt.setVisibility(visiable ? View.VISIBLE : View.GONE);
	}

	/**
	 * 设置标题
	 * 
	 * @param text
	 */
	public void setTitleText(String text) {
		String s = "<font face='隶书'><b>" + text + "</b></font>";
		title_txt.setText(Html.fromHtml(s));
	}

}
